Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate command usage text #10342

Merged
merged 8 commits into from Jan 19, 2021
Merged

Conversation

Rylan12
Copy link
Member

@Rylan12 Rylan12 commented Jan 15, 2021

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?
  • Have you successfully run brew man locally and committed any changes?

This PR uses the new named_args method to generate usage strings for brew help, docs.brew.sh, and the manpage.

For most commands, simply replacing the existing usage_banner with description (removing the old usage line from the beginning) is sufficient.

There are a few commands that needed special attention (e.g. tap or ruby). For these commands, the automatic usage string can be overridden using the usage_string method.

Additionally, aliases (except for instal and uninstal) are now shown in the usage string.

CC @dawidd6, @EricFromCanada, and @MikeMcQuaid

@BrewTestBot
Copy link
Member

Review period will end on 2021-01-18 at 21:05:31 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Jan 15, 2021
Copy link
Contributor

@jonchang jonchang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks awesome! Small feature suggestion that might be useful.

Library/Homebrew/cli/parser.rb Outdated Show resolved Hide resolved
Copy link
Member

@EricFromCanada EricFromCanada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Maybe someday we'll move each named_args line to just before or after the description, but that's a discussion for another time.

@Rylan12
Copy link
Member Author

Rylan12 commented Jan 16, 2021

LGTM. Maybe someday we'll move each named_args line to just before or after the description, but that's a discussion for another time.

I don't think I would be opposed to this. I'd need to see how it looks I guess.


Separately, I'm a little confused about the difference between flag "--foo=" and flag "--foo" and I'm wondering if one of you can clarify.

Based on experimentation, it seems that flag "--foo=" means that one doesn't need to use = when passing something to the flag. flag "--foo" does require =.

# flag "--foo="
brew cmd --foo=bar # works
brew cmd --foo bar # works

# flag "--foo"
brew cmd --foo=bar # works
brew cmd --foo bar # doesn't work (treats `bar` as normal named argument)

It seems that adding = passes OptionParser::REQUIRED_ARGUMENT to @parser.on rather than OptionParser::OPTIONAL_ARGUMENT. The wording here is throwing me off a little bit. Whether or not = is used doesn't seem to determine whether or not an argument is is required. Am I missing something here?

@Rylan12
Copy link
Member Author

Rylan12 commented Jan 16, 2021

Oh wait, I'm wrong. Here's an updated explanation:

# flag "--foo="
brew cmd --foo=bar # args.foo returns "bar"
brew cmd --foo bar # args.foo returns "bar"
brew cmd --foo     # args.foo throws an error: "missing argument: --foo"

# flag "--foo"
brew cmd --foo=bar # args.foo returns "bar"
brew cmd --foo bar # args.foo returns true
brew cmd --foo     # args.foo returns true

So the question becomes: how should flags in the usage string show up? It seems that [--foo=foo] is the safe option. For flags that do require an argument (i.e. with =), should we use [--foo foo] instead? Something else?

In the cases where the argument isn't required, should there be a way to indicate that [--foo] or [--foo=bar] are allowed? Using [--foo[=foo]] or [(--foo|--foo=foo)] feels a little too complex.

@Rylan12
Copy link
Member Author

Rylan12 commented Jan 18, 2021

Maybe someday we'll move each named_args line to just before or after the description, but that's a discussion for another time.

@EricFromCanada I have to say I'm torn about this. I do kind of like them at the end (although I'm not totally sure why). It also adds some consistency with the usage string (in which named args come after options). On the other hand, it's nice to be able to see the named_args at a glance toward the top of the command_args method. I guess I'm leaning toward no change in this PR, but I'd be open to changing it in the future.

@EricFromCanada
Copy link
Member

Just so we're clear, the = at the end of a flag declaration indicates that supplying a value is required, and the lack of one indicates a default value will be passed. For example, brew info --json --all is equivalent to brew info --json=v2 --all.

I'd try to keep complexity down in the usage string, so I'd be fine with just [--foo] for flags with default values and [--foo=] for flags that require a value.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work again @Rylan12! 👍🏻 from me once CI is 🟢

@Rylan12
Copy link
Member Author

Rylan12 commented Jan 18, 2021

Just so we're clear, the = at the end of a flag declaration indicates that supplying a value is required, and the lack of one indicates a default value will be passed. For example, brew info --json --all is equivalent to brew info --json=v2 --all.

The default value isn't actually passed, though, it just needs to be inferred by the code that handles the option.

I'd try to keep complexity down in the usage string, so I'd be fine with just [--foo] for flags with default values and [--foo=] for flags that require a value.

Okay, let's go with this. I like it: not too cluttered and still easy to understand.

@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Jan 18, 2021
@BrewTestBot
Copy link
Member

Review period ended.

I didn't resolve the merge conflict correctly, I believe
@Rylan12 Rylan12 merged commit 67ca8f5 into Homebrew:master Jan 19, 2021
@Rylan12 Rylan12 deleted the command-usage-text branch January 19, 2021 02:52
@BrewTestBot BrewTestBot added the outdated PR was locked due to age label Feb 19, 2021
@Homebrew Homebrew locked as resolved and limited conversation to collaborators Feb 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants